package com.yuanfengPlus.goodsManage.goodsTypeManage.controller;

import com.yuanfengPlus.goodsManage.goodsTypeManage.model.GoodsType;
import com.yuanfengPlus.goodsManage.goodsTypeManage.service.GoodsTypeService;
import com.yuanfengPlus.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/goodsType")
@Api(tags = "商品分类管理", description = "商品分类相关的API")
public class GoodsTypeController {

    @Autowired
    private GoodsTypeService goodsTypeService;

    @ApiOperation(value = "添加商品分类", notes = "添加一个新的商品分类")
    @PostMapping("/add")
    public Result addGoodsType(@RequestBody GoodsType goodsType) {
        return goodsTypeService.addGoodsType(goodsType);
    }

    @ApiOperation(value = "更新商品分类", notes = "更新现有的商品分类")
    @PutMapping("/update")
    public Result updateGoodsType(@RequestBody GoodsType goodsType) {
        return goodsTypeService.updateGoodsType(goodsType);
    }

    @ApiOperation(value = "查询所有商品分类", notes = "查询所有商品分类")
    @GetMapping("/query")
    public Result queryGoodsType() {
        return goodsTypeService.queryGoodsType();
    }

    @ApiOperation(value = "更新商品分类状态", notes = "更新商品分类的状态")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "goodsTypeId", value = "商品分类ID", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "状态", required = true, dataType = "Integer", paramType = "query")
    })
    @PutMapping("/updateStatus")
    public Result updateGoodsTypeStatus(@RequestParam String goodsTypeId, @RequestParam Integer status) {
        return goodsTypeService.updateGoodsTypeStatus(goodsTypeId, status);
    }
}
